home *** CD-ROM | disk | FTP | other *** search
/ Xentax forum attachments archive / xentax.7z / 9146 / BLP Converter.7z / src / BLP Converter / MainForm.cs < prev    next >
Encoding:
Text File  |  2015-05-02  |  2.0 KB  |  73 lines

  1. ∩╗┐namespace BLP_Converter
  2. {
  3.     using System;
  4.     using System.IO;
  5.     using System.Threading.Tasks;
  6.     using System.Windows.Forms;
  7.  
  8.     public partial class MainForm : Form
  9.     {
  10.         private string formCaption;
  11.  
  12.         public MainForm()
  13.         {
  14.             InitializeComponent();
  15.             blpOutput.DragDrop += new DragEventHandler(blpOutput_DragDrop);
  16.             blpOutput.AllowDrop = true;
  17.             formCaption = this.Text;
  18.         }
  19.  
  20.         private void btnOpen_Click(object sender, EventArgs e)
  21.         {
  22.             if (openFileDialog.ShowDialog() == DialogResult.OK)
  23.             {
  24.                 OpenFile(openFileDialog.FileName);
  25.             }
  26.         }
  27.  
  28.         private void MainForm_DragEnter(object sender, DragEventArgs e)
  29.         {
  30.             if (e.Data.GetDataPresent(DataFormats.FileDrop))
  31.             {
  32.                 e.Effect = DragDropEffects.Copy;
  33.             }
  34.         }
  35.  
  36.         private void MainForm_DragDrop(object sender, DragEventArgs e)
  37.         {
  38.             string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
  39.             Task.Factory.StartNew(() =>
  40.             {
  41.                 if (Path.GetExtension(files[0]).ToLower() == ".blp")
  42.                 {
  43.                     OpenFile(files[0]);
  44.                 }
  45.                 else
  46.                 {
  47.                     MessageBox.Show("Unsupported file extension!", "Error");
  48.                 }
  49.             });
  50.         }
  51.  
  52.         private void blpOutput_DragDrop(object sender, DragEventArgs e)
  53.         {
  54.             MainForm_DragDrop(sender, e);
  55.         }
  56.  
  57.         private void OpenFile(string fileName)
  58.         {
  59.             this.Invoke((Action)delegate
  60.             {
  61.                 blpOutput.Clear();
  62.                 this.Text = formCaption + " - " + fileName;
  63.                 blpOutput.Lines = Program.OpenBLP(fileName);
  64.             });
  65.         }
  66.  
  67.         private void btnCopy_Click(object sender, EventArgs e)
  68.         {
  69.             blpOutput.SelectAll();
  70.             blpOutput.Copy();
  71.         }
  72.     }
  73. }